package net.maku.controller;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse;

public class QuickStart {
	 
		/** 商户号 */
	  public static String appid = "wx6ed1af0b9fdd0456";
	  //APPID：wx1574a5cc73751091
	  //mch_id：1676811007

	
	  /** 商户号 */
	  public static String merchantId = "1676811007";

	  /** 商户API私钥路径 */
	  //public static String privateKeyPath = "D:\\workspaces\\workspace202409\\duxinai-end\\cert\\apiclient_cert.p12";
	  public static String privateKeyPath = "D:\\workspaces\\workspace202409\\duxinai-end\\cert\\apiclient_key.pem";

	  
	  /** 商户证书序列号 */
	  public static String merchantSerialNumber = "3C8BB16E5EDCBDF6C814AC5276F239401AC401D3";

	  /** 商户APIV3密钥 */
	  public static String apiV3Key = "oXi4b7pE7YU5QRXCHC30tx5yfXJCAyyC";
	  
	  
	  public static void main(String[] args) {
		    // 使用自动更新平台证书的RSA配置
		    // 一个商户号只能初始化一个配置，否则会因为重复的下载任务报错
		    Config config =
		        new RSAAutoCertificateConfig.Builder()
		            .merchantId(merchantId)
		            .privateKeyFromPath(privateKeyPath)
		            .merchantSerialNumber(merchantSerialNumber)
		            .apiV3Key(apiV3Key)
		            .build();
		    JsapiService service = new JsapiService.Builder().config(config).build();
		    // request.setXxx(val)设置所需参数，具体参数可见Request定义
		    PrepayRequest request = new PrepayRequest();
		    Amount amount = new Amount();
		    amount.setTotal(100);
		    request.setAmount(amount);
		    request.setAppid(appid);
		    request.setMchid(merchantId);
		    request.setDescription("测试商品标题11");
		    request.setNotifyUrl("https://notify_url");
		    /** 商户订单号 说明：商户订单号 */
		    request.setOutTradeNo("out_trade_no_002");
		    Payer payer = new Payer();
		    payer.setOpenid("oyiCY7ZI5zONxJ3f-O_eoV-N1naw");
		    request.setPayer(payer);
		    PrepayResponse response = service.prepay(request);
 
		    System.out.println(response.getPrepayId());
		    System.out.println(response.toString() );
	 
	  
	  }
	  
	  
	  
}
